package top.fangw.tenant.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.fangw.common.core.result.Result;
import top.fangw.tenant.pojo.dto.SysDictDataDto;
import top.fangw.tenant.pojo.entity.SysDictData;
import top.fangw.tenant.service.ISysDictDataService;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用途：字典的数据值 前端控制器
 * </p>
 *
 * @author fangw
 * @since 2024-02-23
 */
@RestController
@RequestMapping("/sys-dict-data")
@Tag(name = "系统字典数据管理")
@RequiredArgsConstructor
public class SysDictDataController {

    private final ISysDictDataService sysDictDataService;

    @Operation(summary = "添加字典数据")
    @PostMapping("/addSysDictData")
    public Result<?> addSysDictData(@RequestBody SysDictDataDto sysDictDataDto){
        sysDictDataService.addSysDictData(sysDictDataDto);
        return Result.success();
    }

    @Operation(summary = "更新字典数据")
    @PutMapping("/updateDictData")
    public Result<?> updateDictData(@RequestBody SysDictDataDto sysDictDataDto){
        sysDictDataService.updateDictData(sysDictDataDto);
        return Result.success();
    }


    @Operation(summary = "删除字典数据")
    @DeleteMapping("/deleteSysDictData")
    public Result<?>deleteSysDictData(@RequestParam("id") String id){
        sysDictDataService.deleteSysDictData(id);
        return Result.success();
    }

    @Operation(summary = "根据字典类型查询字典数据")
    @GetMapping("/queryDictDataByType")
    public Result<?> queryDictDataByType(@RequestParam("type") String type){
        List<Map<String,Object>> resList = sysDictDataService.queryDictDataByType(type);
        return Result.success(resList);
    }

    @Operation(summary = "根据字典类型id查询字典数据列表")
    @GetMapping("/getDictDateByDictId")
    public Result<?> getDictDateByDictId(@RequestParam("dictTypeId") String dictTypeId){
        List<SysDictData> resList = sysDictDataService.getDictDateByDictId(dictTypeId);
        return Result.success(resList);
    }

    @Operation(summary = "根据字典类型，返回map")
    @GetMapping("/getDataByType")
    public Result<?> getDataByType(@RequestParam("type") String type){
        Map<String,String> resMap = sysDictDataService.getDataByType(type);
        return Result.success(resMap);
    }
}
